package minov.parser;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * @brief hello.
 * Popis.
 * Vecsi popis {@link MultipleValueArgument< T extends Object >}
 * alebo {@link MultipleValueArgument< T >}
 * alebo {@link MultipleValueArgument}
 * 
 * @extends MultipleValueArgument
 * @class EnumArgument
 */
public class EnumArgument extends MultipleValueArgument <String> {

   /**
    * Constructs argument that parses enum values.<br>
    * Example:
    * 
    * <pre>
    * String enumValues[] = { "none", "low", "high" };
    * enumArgument = new EnumArgument(&quot;l&quot;, &quot;level&quot;, enumValues, null)
    * </pre>
    * 
    * @param [in] shortName
    *           argument shortcut
    * @param [in] fullName
    *           full name of argument
    * @param [in] enumerationValues
    *           List of the enum type values.
    * @param [in] defaultValues
    *           List of the default values.
    */
   public EnumArgument(String shortName, String fullName,
         ArrayList<String> enumerationValues, String... defaultValues) {

      super(shortName, fullName, defaultValues);

      for (String enumerationString : enumerationValues) {
         _enumerationValues.add(enumerationString);
      }

   }

   /**
    * Function for processing one argument. Called by the parser.
    * @param [in] text value to be processed
    * @return processed value
    */
   @Override
   public String parseOneArgument(String text) throws Exception {
      return text;
   }

   private Set<String> _enumerationValues = new HashSet<String>();

   private static final String BAD_ENUM_FORMAT_STRING =
         "Argument %s has invalid value %s.";

   
   /**
    * Function for validating one argument value.
    * @param [in] value value to be validated
    * @return ValidationResult object with the result
    */
   @Override
   public ValidationResult validateValue(String value) {

      if (_enumerationValues.contains(value) == false) {
         return ValidationResult.createInvalidResponse(String.format(
               BAD_ENUM_FORMAT_STRING, getDefaultName(), value));
      }

      return ValidationResult.createValidResponse();
   }

   /**
    * Function for returning specific array type for this class. 
    * @return array of the specific type
    */
   @Override
   String[] getGenericArray() {
      return new String[0];
   }

}
